﻿package export.microshop
{
	import com.dusk.util.TextUtil;
	import com.game.data.vo.EquipmentVO;
	import com.game.data.vo.PlayerDataVO;
	import com.game.event.GameEvent;
	import com.game.manager.GameSceneManager;
	import com.game.manager.NotificationManager;
	
	import config.Config;
	
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	public class Micropayment extends Sprite
	{
		
		internal static var needLh:int = 0;
		
		public function Micropayment()
		{
			super();
			TextUtil.redrawTxtOld(this, ["txt_page", "txt_money"]);
			this.sellbsList = [];
			this.sellcwList = [];
			this.sellszList = [];
			this.selldjList = [];
			this.gc = Config.getIns();
			this.player = this.gc.playerData;
			this.addEventListener(Event.ADDED_TO_STAGE, this.added, false, 0, true);
			this.addEventListener(Event.REMOVED_FROM_STAGE, this.removed, false, 0, true);
		}
		
		public var btn_back:SimpleButton;
		public var btn_cz:SimpleButton;
		public var btn_play1:SimpleButton;
		public var btn_play2:SimpleButton;
		public var btn_buyall:SimpleButton;
		public var btn_buybs:SimpleButton;
		public var btn_buysz:SimpleButton;
		public var btn_buycw:SimpleButton;
		public var btn_buydj:SimpleButton;
		public var btn_upPage:SimpleButton;
		public var btn_nextPage:SimpleButton;
		public var txt_page:TextField;
		public var txt_money:TextField;
		public var st0:ShopThing;
		public var st1:ShopThing;
		public var st2:ShopThing;
		public var st3:ShopThing;
		public var st4:ShopThing;
		public var st5:ShopThing;
		public var st6:ShopThing;
		public var st7:ShopThing;
		public var st8:ShopThing;
		internal var playerbtnState:*;
		private var gc:Config;
		private var player:PlayerDataVO;
		private var sellbsList:Array;
		private var sellcwList:Array;
		private var sellszList:Array;
		private var selldjList:Array;
		private var selectTag:uint = 1;
		private var pageNum:uint = 1;
		private var curPage:uint = 1;
		private var allmoney:int = 0;
		private var lastBtn:String = "";
		private var btnState:*;
		
		public function getUser():PlayerDataVO
		{
			return this.player;
		}
		
		public function getAllMoney():int
		{
			return this.allmoney;
		}
		
		private function setShopThingEquipment():void
		{
			var _loc1_:* = [];
			switch (this.selectTag)
			{
				case 1:
					if (this.sellbsList.length > 0)
					{
						_loc1_ = _loc1_.concat(this.sellbsList);
					}
					if (this.sellcwList.length > 0)
					{
						_loc1_ = _loc1_.concat(this.sellcwList);
					}
					if (this.sellszList.length > 0)
					{
						_loc1_ = _loc1_.concat(this.sellszList);
					}
					if (this.selldjList.length > 0)
					{
						_loc1_ = _loc1_.concat(this.selldjList);
						break;
					}
					break;
				case 2:
					_loc1_ = this.sellbsList;
					break;
				case 3:
					_loc1_ = this.sellcwList;
					break;
				case 4:
					_loc1_ = this.sellszList;
					break;
				case 5:
					_loc1_ = this.selldjList;
			}
			var _loc2_:int = 0;
			while (_loc2_ < 9)
			{
				(this["st" + _loc2_] as ShopThing).clearEquipment();
				this["st" + _loc2_].visible = true;
				if (_loc1_[_loc2_ + (this.curPage - 1) * 9])
				{
					(this["st" + _loc2_] as ShopThing).setEquipment(_loc1_[_loc2_ + (this.curPage - 1) * 9]);
				}
				else
				{
					this["st" + _loc2_].visible = false;
				}
				_loc2_++;
			}
			var _loc3_:uint = int(_loc1_.length);
			this.pageNum = int(Math.ceil(_loc3_ / 9));
			if (this.pageNum == 0)
			{
				this.pageNum = 1;
			}
			this.setTxt();
		}
		
		private function setTxt():void
		{
			this.txt_page.text = this.curPage + "/" + this.pageNum;
			this.txt_money.text = this.allmoney + "";
		}
		
		public function getMoneySuccess(param1:GameEvent):void
		{
			this.allmoney = int(param1.data[0]);
			this.setTxt();
			var _loc2_:int = 0;
			while (_loc2_ < 9)
			{
				this["st" + _loc2_].getMoneySuccess();
				_loc2_++;
			}
		}
		
		private function added(param1:Event):void
		{
			this.sellbsList.push(this.gc.allEquip.findByName("wpqhs1"));
			this.sellbsList.push(this.gc.allEquip.findByName("wpqhs2"));
			this.sellbsList.push(this.gc.allEquip.findByName("wpqhs3"));
			this.sellbsList.push(this.gc.allEquip.findByName("wpqhs4"));
			this.sellbsList.push(this.gc.allEquip.findByName("sms2"));
			this.sellbsList.push(this.gc.allEquip.findByName("sms3"));
			this.sellbsList.push(this.gc.allEquip.findByName("mfs2"));
			this.sellbsList.push(this.gc.allEquip.findByName("mfs3"));
			this.sellbsList.push(this.gc.allEquip.findByName("gjs2"));
			this.sellbsList.push(this.gc.allEquip.findByName("gjs3"));
			this.sellbsList.push(this.gc.allEquip.findByName("fys2"));
			this.sellbsList.push(this.gc.allEquip.findByName("fys3"));
			this.sellbsList.push(this.gc.allEquip.findByName("wphlz"));
			this.sellbsList.push(this.gc.allEquip.findByName("wpslz"));
			this.sellbsList.push(this.gc.allEquip.findByName("wptlz"));
			this.sellbsList.push(this.gc.allEquip.findByName("wpllz"));
			this.sellbsList.push(this.gc.allEquip.findByName("wpflz"));
			this.sellbsList.push(this.gc.allEquip.findByName("wpxyf"));
			this.sellbsList.push(this.gc.allEquip.findByName("wpbdf"));
			this.selldjList.push(this.gc.allEquip.findByName("mpyj"));
			this.selldjList.push(this.gc.allEquip.findByName("css6"));
			this.selldjList.push(this.gc.allEquip.findByName("css12"));
			this.selldjList.push(this.gc.allEquip.findByName("css18"));
			this.selldjList.push(this.gc.allEquip.findByName("css_2"));
			this.selldjList.push(this.gc.allEquip.findByName("css_3"));
			this.selldjList.push(this.gc.allEquip.findByName("wwdgl"));
			this.selldjList.push(this.gc.allEquip.findByName("yll"));
			this.selldjList.push(this.gc.allEquip.findByName("wplwl"));
			this.selldjList.push(this.gc.allEquip.findByName("wpbsz"));
			this.selldjList.push(this.gc.allEquip.findByName("ttlpsp1"));
			this.selldjList.push(this.gc.allEquip.findByName("ttlpsp2"));
			this.selldjList.push(this.gc.allEquip.findByName("ttlpsp3"));
			this.sellcwList.push(this.gc.allEquip.findByName("wpcsd"));
			this.sellcwList.push(this.gc.allEquip.findByName("wphhd"));
			this.sellcwList.push(this.gc.allEquip.findByName("cwjnxld"));
			this.sellcwList.push(this.gc.allEquip.findByName("cwzzxld"));
			this.sellcwList.push(this.gc.allEquip.findByName("djyys"));
			this.sellszList.push(this.gc.allEquip.findByName("ptnmwsz"));
			this.sellszList.push(this.gc.allEquip.findByName("ptzlwsz"));
			this.sellszList.push(this.gc.allEquip.findByName("ptsmsrsz"));
			this.sellszList.push(this.gc.allEquip.findByName("ptttzssz"));
			this.gc.eventManager.addEventListener("BuySuccess", this.buySuccess);
			this.gc.eventManager.addEventListener("GetMoneySuccess", this.getMoneySuccess);
			this.btn_back.addEventListener(MouseEvent.CLICK, this.backClick);
			this.btn_cz.addEventListener(MouseEvent.CLICK, this.czClick);
			this.btn_play1.addEventListener(MouseEvent.CLICK, this.play1Click);
			this.btn_play2.addEventListener(MouseEvent.CLICK, this.play2Click);
			this.btn_buycw.addEventListener(MouseEvent.CLICK, this.buycwClick);
			this.btn_buyall.addEventListener(MouseEvent.CLICK, this.buyallClick);
			this.btn_buysz.addEventListener(MouseEvent.CLICK, this.buyszClick);
			this.btn_buybs.addEventListener(MouseEvent.CLICK, this.buybsClick);
			this.btn_buydj.addEventListener(MouseEvent.CLICK, this.buydjClick);
			this.btn_upPage.addEventListener(MouseEvent.CLICK, this.upPageClick);
			this.btn_nextPage.addEventListener(MouseEvent.CLICK, this.nextPageClick);
			if (this.gc.playNum == 1)
			{
				this.btn_play2.visible = false;
			}
			else
			{
				this.btn_play2.visible = true;
			}
			this.btn_play1.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
			this.btn_buyall.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
		}
		
		private function removed(param1:Event):void
		{
			this.gc.eventManager.removeEventListener("BuySuccess", this.buySuccess);
			this.gc.eventManager.removeEventListener("GetMoneySuccess", this.getMoneySuccess);
			this.btn_back.removeEventListener(MouseEvent.CLICK, this.backClick);
			this.btn_cz.removeEventListener(MouseEvent.CLICK, this.czClick);
			this.btn_play1.removeEventListener(MouseEvent.CLICK, this.play1Click);
			this.btn_play2.removeEventListener(MouseEvent.CLICK, this.play2Click);
			this.btn_buycw.removeEventListener(MouseEvent.CLICK, this.buycwClick);
			this.btn_buyall.removeEventListener(MouseEvent.CLICK, this.buyallClick);
			this.btn_buysz.removeEventListener(MouseEvent.CLICK, this.buyszClick);
			this.btn_buybs.removeEventListener(MouseEvent.CLICK, this.buybsClick);
			this.btn_buydj.removeEventListener(MouseEvent.CLICK, this.buydjClick);
			this.btn_upPage.removeEventListener(MouseEvent.CLICK, this.upPageClick);
			this.btn_nextPage.removeEventListener(MouseEvent.CLICK, this.nextPageClick);
			this.btnState = null;
			this.player = null;
		}
		
		private function backClick(param1:MouseEvent):void
		{
			GameSceneManager.getIns().switchScene(GameSceneManager.GAME_MAP);
			if (this.parent)
			{
				this.parent.removeChild(this);
			}
		}
		
		private function czClick(param1:MouseEvent):void
		{
			NotificationManager.alert("单机版请用灵魂购买~");
		}
		
		private function play1Click(param1:MouseEvent):void
		{
			this.player = this.gc.playerData;
			this.setTxt();
			this.gc.eventManager.dispatchEvent(new GameEvent("ChangePlayer"));
			if (this.btn_play1.upState != this.btn_play1.overState)
			{
				if (this.playerbtnState)
				{
					this.btn_play2.upState = this.playerbtnState;
				}
				this.playerbtnState = param1.target.upState;
				param1.target.upState = param1.target.overState;
			}
		}
		
		private function play2Click(param1:MouseEvent):void
		{
			this.player = this.gc.playerData;
			this.setTxt();
			this.gc.eventManager.dispatchEvent(new GameEvent("ChangePlayer"));
			if (this.btn_play2.upState != this.btn_play2.overState)
			{
				if (this.playerbtnState)
				{
					this.btn_play1.upState = this.playerbtnState;
				}
				this.playerbtnState = param1.target.upState;
				param1.target.upState = param1.target.overState;
			}
		}
		
		private function buyallClick(param1:MouseEvent):void
		{
			this.selectTag = 1;
			this.curPage = 1;
			this.setShopThingEquipment();
			if (this.btnState)
			{
				if (this.lastBtn != "")
				{
					this[this.lastBtn].upState = this.btnState;
				}
			}
			this.lastBtn = "btn_buyall";
			this.btnState = param1.target.upState;
			param1.target.upState = param1.target.downState;
		}
		
		private function buybsClick(param1:MouseEvent):void
		{
			this.selectTag = 2;
			this.curPage = 1;
			this.setShopThingEquipment();
			if (this.btnState)
			{
				if (this.lastBtn != "")
				{
					this[this.lastBtn].upState = this.btnState;
				}
			}
			this.lastBtn = "btn_buybs";
			this.btnState = param1.target.upState;
			param1.target.upState = param1.target.downState;
		}
		
		private function buydjClick(param1:MouseEvent):void
		{
			this.selectTag = 5;
			this.curPage = 1;
			this.setShopThingEquipment();
			if (this.btnState)
			{
				if (this.lastBtn != "")
				{
					this[this.lastBtn].upState = this.btnState;
				}
			}
			this.lastBtn = "btn_buydj";
			this.btnState = param1.target.upState;
			param1.target.upState = param1.target.downState;
		}
		
		private function buycwClick(param1:MouseEvent):void
		{
			this.selectTag = 3;
			this.curPage = 1;
			this.setShopThingEquipment();
			if (this.btnState)
			{
				if (this.lastBtn != "")
				{
					this[this.lastBtn].upState = this.btnState;
				}
			}
			this.lastBtn = "btn_buycw";
			this.btnState = param1.target.upState;
			param1.target.upState = param1.target.downState;
		}
		
		private function buyszClick(param1:MouseEvent):void
		{
			this.selectTag = 4;
			this.curPage = 1;
			this.setShopThingEquipment();
			if (this.btnState)
			{
				if (this.lastBtn != "")
				{
					this[this.lastBtn].upState = this.btnState;
				}
			}
			this.lastBtn = "btn_buysz";
			this.btnState = param1.target.upState;
			param1.target.upState = param1.target.downState;
		}
		
		private function upPageClick(param1:MouseEvent):void
		{
			if (this.curPage > 1)
			{
				--this.curPage;
				this.setShopThingEquipment();
				this.setTxt();
			}
		}
		
		private function nextPageClick(param1:MouseEvent):void
		{
			if (this.curPage < this.pageNum)
			{
				++this.curPage;
				this.setShopThingEquipment();
				this.setTxt();
			}
		}
		
		private function buySuccess(param1:GameEvent):void
		{
			var _loc2_:* = null;
			var _loc3_:int = 0;
			var _loc4_:* = null;
			var _loc5_:int = 0;
			var _loc6_:int = 0;
			var _loc7_:* = null;
			player.reduceLhValue(Micropayment.needLh);
			this.allmoney = param1.data[0];
			this.setTxt();
			var _loc8_:int = 0;
			while (_loc8_ < 9)
			{
				_loc2_ = this["st" + _loc8_].getNumAndEquip();
				if (_loc2_.thingnum != 0)
				{
					if (this.selectTag == 1)
					{
						_loc3_ = 0;
						while (_loc3_ < _loc2_.thingnum)
						{
							if (EquipmentVO(_loc2_.equip).type == "zbsz" || EquipmentVO(_loc2_.equip).type == "zbcb")
							{
								(_loc4_ = this.gc.allEquip.findByName(EquipmentVO(_loc2_.equip).equipId)).setFashionTime(this.gc.curDate);
								this.player.bugConsumeList.push(_loc4_);
							}
							else if (EquipmentVO(_loc2_.equip).type == "zbwp" || EquipmentVO(_loc2_.equip).type == "wpqhs")
							{
								this.gc.putQhsInBackPack(this.player, EquipmentVO(_loc2_.equip).equipId);
							}
							else
							{
								this.player.bagEquipList.push(_loc2_.equip);
							}
							_loc3_++;
						}
					}
					else if (this.selectTag == 2 || this.selectTag == 5 || this.selectTag == 3)
					{
						_loc5_ = 0;
						while (_loc5_ < _loc2_.thingnum)
						{
							this.gc.putQhsInBackPack(this.player, _loc2_.equip.equipId);
							_loc5_++;
						}
					}
					else if (this.selectTag == 4)
					{
						_loc6_ = 0;
						while (_loc6_ < _loc2_.thingnum)
						{
							_loc7_ = this.gc.allEquip.findByName(EquipmentVO(_loc2_.equip).equipId);
							this.player.bugConsumeList.push(_loc7_);
							_loc6_++;
						}
					}
					this["st" + _loc8_].buySuccess();
				}
				_loc8_++;
			}
			this.gc.memory.setStorage();
		}
		
		public static function getSellPrice(param1:String):int
		{
			var price:int = 0;
			switch (param1)
			{
				case "wpqhs1":
					price = 8000;
					break;
				case "gjs1":
				case "sms1":
					price = 5000;
					break;
				case "fys1":
				case "mfs1":
					price = 5000;
					break;
				case "ptsmsrsz":
				case "wpqhs2":
					price = 20000;
					break;
				case "sms2":
				case "gjs2":
					price = 14000;
					break;
				case "fys2":
				case "mfs2":
					price = 14000;
					break;
				case "wpqhs3":
					price = 52000;
					break;
				case "wphlz":
				case "wpslz":
				case "wptlz":
				case "wpllz":
				case "wpflz":
				case "sms3":
				case "gjs3":
				case "mfs3":
				case "fys3":
					price = 35000;
					break;
				case "wpqhs4":
					price = 135000;
					break;
				case "wpxyf":
					price = 35000;
					break;
				case "wpbdf":
				case "mpyj":
				case "ptzlwsz":
				case "ptnmwsz":
					price = 30000;
					break;
				case "ptttzssz":
					price = 80000;
					break;
				case "wphhd":
					price = 35000;
					break;
				case "wpcsd":
					price = 35000;
					break;
				case "cwjnxld":
				case "cwzzxld":
				case "djyys":
					price = 50000;
					break;
				case "tss":
				case "yhs":
					price = 150000;
					break;
				case "css6":
					price = 12000;
					break;
				case "css12":
					price = 21000;
					break;
				case "css18":
					price = 30000;
					break;
				case "yll":
				case "wpbsz":
				case "wplwl":
					price = 40000;
					break;
				case "wwdgl":
					price = 10000;
					break;
				case "css_2":
					price = 70000;
					break;
				case "css_3":
					price = 100000;
					break;
				case "ttlpsp1":
				case "ttlpsp2":
				case "ttlpsp3":
					price = 100000;
					break;
				default:
					price = 10000000;
			}
			return price;
		}
	}
}
